package com.woniuxy.yogaapp.service.imp;

import com.woniuxy.yogaapp.dto.Count;
import com.woniuxy.yogaapp.dto.UidDto;
import com.woniuxy.yogaapp.mapper.CoachMapper;
import com.woniuxy.yogaapp.mapper.OrderShowMapper;
import com.woniuxy.yogaapp.mapper.StudentMapper;
import com.woniuxy.yogaapp.pojo.Coach;
import com.woniuxy.yogaapp.pojo.OrderClass;
import com.woniuxy.yogaapp.pojo.Student;
import com.woniuxy.yogaapp.service.OrderShowService;
import lombok.Data;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*
 *@author：源
 *@date:16:52:02
 *@descripion
 */
@Service
@Data
public class OrderShowServiceImp implements OrderShowService {
	@Resource
	private OrderShowMapper orderShowMapper;
	@Resource
	private StudentMapper studentMapper;
	@Resource
	private CoachMapper coachMapper;

	@Override
	public List<OrderClass> selectOrder(UidDto uidDto) {
		// 1.查rid通过uid
		uidDto.setPay(true);
		System.out.println(uidDto.getUid());
		Integer rid = orderShowMapper.selectRidByuid(uidDto);
		System.out.println(rid);
		if (rid == 2) {
			System.out.println("学员");
			uidDto.setSid(studentMapper.findStudentByUid(new Student(uidDto.getUid())).getSid());

			System.out.println("**********2");
			List<OrderClass> list = orderShowMapper.selectOrder(uidDto);

			return list;
		} else if (rid == 3) {
			System.out.println("教练");
			uidDto.setCid(coachMapper.findCoachByUid(new Coach(uidDto.getUid())).getCid());

			System.out.println("**********3");
			List<OrderClass> list = orderShowMapper.selectOrder(uidDto);
			return list;
		}
		return null;
	}

	@Override
	public Count selectCount(Student student) {
		// 通过id

		int sid = studentMapper.findStudentByUid(student).getSid();
		Count count4 = orderShowMapper.selectCount4(sid);
		Count count6 = orderShowMapper.selectCount6(sid);
		count4.setCount6(count6.getCount6());
		return count4;
	}

	@Override
	public Count selectCountc(Coach coach) {
		System.out.println(coach);
		int cid = coachMapper.findCoachByUid(coach).getCid();
		Count countc = orderShowMapper.selectCountc(cid);

		return countc;
	}
}
